<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>


<!DOCTYPE HTML>
<html style="overflow: auto;">
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="static/html5shiv.js"></script>
<script type="text/javascript" src="static/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/css/friends/all_7ea23d2.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/css/friends/global.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/css/friends/mbox-theme.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/css/friends/reset.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/css/friends/widget_ccf50cd.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/Hui-iconfont/1.0.8/iconfont.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/css/magic-input.min.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/Hui-iconfont/1.0.8/iconfont.css" />
<!--[if IE 6]>
<script type="text/javascript" src="static/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>好友分享</title>
<style type="text/css">
.friend-list{
height:665px;
width:100%;
float:right;
overflow-y:auto;
overflow-x:hidden;
}
.session-content-wrap{
height:726px;
width:100%;
float:right;
overflow-y:auto;
overflow-x:hidden;
}

::-webkit-scrollbar {display:none}

body .mySkin .layui-layer-title {
    padding: 0 80px 0 20px;
    height: 42px;
    line-height: 42px;
    border-bottom: 1px solid #c4dbfe;
    font-size: 14px;
    color: #333;
    overflow: hidden;
    background-color: #f2f6fd;
    border-radius: 4px 4px 0 0;
}
</style>
</head>
  
<body>
<input type="hidden" id="valid" value="">
<input type="hidden" id="set-remark" value="">
<input type="hidden" id="remark" value="">
<div id="document">
	<div id="body" class="clearfix">
		<div class="mbox-main">
			<div class="skin-main"></div>
			<div class="main-section" style="height: 850px;">
				<div class="main-section-special" style="visibility: visible;">
					<div class="module-sectionLists">
						<ul class="header-tabs global-clearfix">
							<li class="tabs-item friend-item">
								<a data-sharetype="session" class="item on" href="javascript:;">
									<i class="Hui-iconfont" style="font-size: 18px">&#xe686;</i>
									<b>会话</b>
									<span class="subline"></span>
								</a>
							</li>
							<li class="tabs-item friend-item">
								<a data-sharetype="friend" class="item" href="javascript:;">
									<i class="Hui-iconfont" style="font-size: 18px">&#xe60d;</i>
									<b>好友</b>
								</a>
							</li>
						</ul>
						<div class="list-content-box" style="height: 726px;overflow: hidden;">
							<div class="session-content tab-content" style="display:block;margin-top: 0px">
								<div class="session-content-wrap">
									<ul class="session-list"></ul>
								</div>
							</div>
							<div class="friend-content tab-content" style="display: none;margin-top: 0px">
								<div class="group-content-wrap" style="display: block;">
									<ul class="session-list">
										<li class="session-list-item">
											<a class="avatar service-icon-newfriend" href="javascript:;"></a>
											<p class="user-name service-name-newfriend">新好友</p>
											<p class="last-time show-time"></p>
											<p class="new-session show-session"></p>
										</li>
									</ul>
								</div>
								<div class="friend-content-wrap">
									<ul class="friend-list"></ul>
								</div>
							</div>
						</div>
						<div class="sectionLists-btn-area">
							<!-- <a class="sectionLists-btn create-group-btn" href="javascript:;">
								<b>创建群组</b>
							</a>
							<span class="subline"></span> -->
							<a class="sectionLists-btn addfriend-btn" href="javascript:;">
								<b>添加好友</b>
							</a>
							<span class="subline"></span>
							<a class="sectionLists-btn setup-btn" href="javascript:;">
								<b>设置</b>
							</a>
						</div>
					</div>
					<div class="module-content-all">
						<h2 class="header header-show" style="display: none;">
							<div class="file-factory open">
								<span class="button">
									<em class="icon"></em>
									<span class="name">文件库</span>
								</span>
							</div>
						</h2>
						<div class="all-main-content" style="height: 831px">
							<div class="sharelist-shareViews" style="display: none;">
								<div class="sharelist-view-toggle">
									<div class="sharelist-operate-btns" style="display: none;">
										<a class="btn btn-secondary-outline radius" data-type = "save">
											<i class="Hui-iconfont" style="font-size: 16px">&#xe644;</i>
											<span class="btn-val">保存</span>
										</a>
										<a class="btn btn-secondary-outline radius" data-type = "download">
											<i class="Hui-iconfont" style="font-size: 16px">&#xe641;</i>
											<span class="btn-val">下载</span>
										</a>
										<a class="btn btn-secondary-outline radius" data-type = "del">
											<i class="Hui-iconfont" style="font-size: 16px">&#xe6e2;</i>
											<span class="btn-val">删除</span>
										</a>
									</div>
								</div>
								<div class="module-sharelist" style="display: none">
									<div class="sharelist-header">
										<ul class="sharelist-tips global-clearfix">
											<li class="sharelist-tips-title">全部文件</li>
										</ul>
										<ul class="sharelist-columns global-clearfix" style="padding-right: 15px">
											<li class="sharelist-column-checkbox">
												<input class="mgc mgc-primary" type="checkbox" name="check-all" id="check-all" data-id="">
											</li>
											<li class="sharelist-column-name">文件名</li>
											<li class="sharelist-column-size">大小</li>
											<li class="sharelist-column-sname">分享人</li>
											<li class="sharelist-column-date">分享时间</li>
										</ul>
									</div>
									<div class="sharelist-container" style="height: 714px;">
										<ul class="global-clearfix"></ul>
									</div>	
								</div>
							</div>				
						</div>
						<div class="user-info-content" style="display: none;">
							<div class="user-info-mainbox"></div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<div class="module-mgr-session" style="left: 415px;top: 153px;display: none;">
	<ul class="operate-downlist-inner">
		<li class="operate-downlist-item" style="display: none">
			<a href="javascript:;">删除并退出群组</a>
		</li>
		<li class="operate-downlist-item" style="display: list-item;">
			<a href="javascript:;">删除会话</a>
		</li>
	</ul>
</div>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="${pageContext.request.contextPath}/static/layer/2.4/layer.js"></script>

<script type="text/javascript" src="${pageContext.request.contextPath}/static/laypage/1.2/laypage.js"></script>
<script type="text/javascript">
$(function(){

	var application , friends , _session , _count = -1 , _sessionCount = -1;
	
	friendSession = function(){
		$.ajax({
			type: "post",
			url : "session-list.action",
			dataType: "json",
			success : function(_data){
				_session = _data.data;
				var html = "";
				$.each(_data.data,function(index,content){
					if(content.count == 0){
						html +=
						'<li class="session-list-item session-list-add" id = "'+content.id+'">'
							+'<a class="avatar" href="javascript:;">'
								+'<img src="${pageContext.request.contextPath}/static/avatars/user.jpg">'
							+'</a>'
							+'<p class="user-name" title="">'+content.showInfo+'</p>'
							+'<p class="last-time show-time">'+content.newSharingTime+'</p>'
							+'<p class="new-session show-session">分享文件'+content.newTitle+'</p>'
							+'<a class="operate-btn" href="javascript:;" id="100"></a>'
						+'</li>';
					}else{
						html +=
						'<li class="session-list-item session-list-add" id = "'+content.id+'">'
							+'<a class="avatar" href="javascript:;">'
								+'<img src="${pageContext.request.contextPath}/static/avatars/user.jpg">'
							+'</a>'
							+'<p class="user-name" title="">'+content.showInfo+'</p>'
							+'<p class="last-time show-time">'+content.newSharingTime+'</p>'
							+'<p class="new-session show-session">分享文件'+content.newTitle+'</p>'
							+'<a class="operate-btn" href="javascript:;" id="100"></a>'
							+'<p class="new-num-session show-num">'+content.count+'</p>'
						+'</li>';
					}
				});
				$(".session-content-wrap .session-list").html(html);
			}
		});
	}
	
	friendSession();
	
	$(".header-tabs a").click(function(){
		$(".header-tabs a").removeClass('on');
		$(this).addClass('on');
		if($(this).attr('data-sharetype') == 'session'){
			$(".user-info-content").hide();
			$(".session-content").show();
			$(".friend-content").hide();
			$(".friend-content li").removeClass('selected');
			_count = -1;
			$(".user-info-mainbox").html("");
			friendSession();
		}else if($(this).attr('data-sharetype') == 'friend'){
			$(".user-info-content").show();
			$(".header-show").hide();
			$(".session-content").hide();
			$(".friend-content").show();
			$(".module-sharelist").hide();
			$(".session-content li").removeClass('selected');
			var error;
			$.ajax({
				url : "application.action",
				dataType: "json",
				async : false,
				success : function(_data){
					application =  _data.data;
					error = _data.msg;
				}
			});
			if(application != null){
				$(".friend-content .last-time").text(application[0].createdtime);
				$(".friend-content .new-session").text(application[0].decode_applicant + "等添加你为好友");
				if(application[0].count > 0){
					$(".friend-content .session-list-item").append('<p class="new-num-session show-num">'+application[0].count+'</p>');
				}
			}else{
				$(".friend-content .last-time").text(error);
				$(".friend-content .new-session").text("暂无好友请求");
			}
			var count = -1;
			$.ajax({
				url: "friend-list.action",
				dataType: "json",
				async : false,
				success : function(_data){
					friends =  _data.data;
					var html = "";
					$.each(_data.data,function(index,content){
						if($("#valid").val() != ""){
							if($("#valid").val() == content.username){
								count = index;
							}
						}
						if(content.remark != null){
							html += 
							'<li class="friend-list-item friend-list-add">'
								+'<a href="javascript:;" class="avatar">'
									+'<img src="${pageContext.request.contextPath}/static/avatars/user.jpg">'
								+'</a>'
								+'<p class="user-name">'+content.remark+'</p>'
							+'</li>'
						}else if(content.nickname != "-"){
							html += 
							'<li class="friend-list-item friend-list-add">'
								+'<a href="javascript:;" class="avatar">'
									+'<img src="${pageContext.request.contextPath}/static/avatars/user.jpg">'
								+'</a>'
								+'<p class="user-name">'+content.nickname+'</p>'
							+'</li>'
						}else{
							html += 
							'<li class="friend-list-item friend-list-add">'
								+'<a href="javascript:;" class="avatar">'
									+'<img src="${pageContext.request.contextPath}/static/avatars/user.jpg">'
								+'</a>'
								+'<p class="user-name">'+content.encryptionName+'</p>'
							+'</li>'
						}
					});
					
					$(".friend-content-wrap .friend-list").html(html);
					
					if(count != -1){
						$(".friend-content-wrap .friend-list-item").eq(count).click();
					}
					
					if(_count != -1){
						$(".friend-content-wrap .friend-list-item").eq(_count).click();
					}
				}
			});
			
		}
	});
	
	
	$(".list-content-box").on("mouseenter","li",function(){
		$(this).addClass('hover').siblings().removeClass('hover');
		x = $(this).find(".operate-btn").offset();
		if(!$(this).find(".operate-btn").hasClass('open') || event.target.nodeName != "A"){
			$(".module-mgr-session").hide();
		}
	});
	
	$(".list-content-box").on("mouseleave","li",function(){
		div = $(".session-content-wrap");
		divX = div.offset();
		areaWidth = divX.left + div.width();
		areaHeight = divX.top + div.height();
		eventX = event.clientX;
		eventY = event.clientY;
		if(eventX < divX.left || eventX > areaWidth || eventY < divX.top || eventY > areaHeight){
			$(".list-content-box li").removeClass('hover');
		}
	});
	
	$(".session-list").on("mouseenter",".operate-btn",function(){
		$(".operate-btn").removeClass('open');
    	$(this).addClass('open');
    	id = $(this).attr("id");
    	x = $(this).offset();
    	$(".module-mgr-session").css("left",x.left);
    	$(".module-mgr-session").css("top",x.top - 5);
    	$(".module-mgr-session").show();
    	$(".operate-downlist-item").attr("data-id",$(this).parent().attr("id"));
	});
	
	$(".module-mgr-session").hover(function(){
	},function(){
		$(".list-content-box li").removeClass('hover');
		$(this).hide();
	})
	
	$(".list-content-box").on("click","li",function(){
		$(".list-content-box li").removeClass('selected');
        $(this).addClass('selected');
	});
	
	$(".addfriend-btn").click(function(){
		var index = layer.open({
			type: 2,
			area: ['570px','350px'],
			title: '添加好友',
			skin:'mySkin',
			content:"/nebula/add-friend.action"
		});
	});
	
	$(".setup-btn").click(function(){
		var index = layer.open({
			type: 2,
			area: ['614px','180px'],
			title: '个人设置',
			skin:'mySkin',
			content:"/nebula/personal-settings.action"
		});
	});
	
	$(".group-content-wrap").on("click",".session-list-item",function(){
		_count = -1;
		$(".friend-content .new-num-session").remove();
		$.ajax({
			url : "update-view.action",
		});
		var html = "";
		if(application != null){
			$.each(application,function(index,content){
				if(content.state == 0){
					html += 
					'<dl class="user-module">'
						+'<dt>'
							+'<img alt="" src="${pageContext.request.contextPath}/static/avatars/user.jpg" width="45" height="45">'
						+'</dt>'
						+'<dd>'
							+'<p class="user-name">'+content.decode_applicant+'</p>'
							+'<p class="user-name user-name-desc">'+content.messages+'</p>'
						+'</dd>'
						+'<dd>'
							+'<a class="shareFile" href="javascript:;" data-index="'+index+'">分享文件</a>'
							+'<a class="addFriend" href="javascript:;">加为好友</a>'
						+'</dd>'
					+'</dl>';
				}else if(content.state == 1){
					html += 
					'<dl class="user-module">'
						+'<dt>'
							+'<img alt="" src="${pageContext.request.contextPath}/static/avatars/user.jpg" width="45" height="45">'
						+'</dt>'
						+'<dd>'
							+'<p class="user-name">'+content.decode_applicant+'</p>'
							+'<p class="user-name user-name-desc">'+content.messages+'</p>'
						+'</dd>'
						+'<dd>'
							+'<a class="shareFile" href="javascript:;" data-index="'+index+'">分享文件</a>'
							+'<a class="addFriend added" href="javascript:;">已添加</a>'
						+'</dd>'
					+'</dl>';
				}
			});
		}
		$(".user-info-mainbox").css({"width":"","margin-top":"","margin-left":""});
		$(".user-info-mainbox").css({"width":"100%","margin-top":"19px","position":"static"});
		$(".user-info-mainbox").html(
			'<div class="user-list-main friend-recom-list">'
				+'<div class="list-main-title">新好友通知</div>'
				+'<div class="list-main-content" style="height: 791px">'+html+'</div>'
			+'</div>'
		);
	});
	
	$(".friend-content-wrap").on("click",".friend-list-item",function(){
		_count = $(this).index();
		$(".user-info-mainbox").css({"width":"","margin-top":"","position":""});
        $(".user-info-mainbox").css({"width":"500px","margin-top":"-221px","margin-left":"-250px"});
        $("#set-remark").val(friends[$(this).index()].username);
        var html;
        if(friends[$(this).index()].remark != null){
        	$("#remark").val(friends[$(this).index()].remark);
        	if(friends[$(this).index()].nickname != "-"){
	        	html = 
	        	'<div class="user-info-main">'
					+'<div class="user-info-summary">'
						+'<div class="userPhoto">'
							+'<img alt="" src="${pageContext.request.contextPath}/static/avatars/user.jpg">'
						+'</div>'
						+'<div class="userName">'+friends[$(this).index()].remark+'</div>'
					+'</div>'
					+'<div class="user-info-detail clearfix">'
						+'<div class="title">'
							+'<p>备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注：</p>'
							+'<p>昵&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;称：</p>'
							+'<p>大岭山中学网盘账号：</p>'
						+'</div>'
						+'<div class="text">'
							+'<p>'
								+friends[$(this).index()].remark
								+'<a href="javascript:;" class="remarkButton" title="修改备注"></a>'
							+'</p>'
							+'<p>'+friends[$(this).index()].nickname+'</p>'
							+'<p>'+friends[$(this).index()].encryptionName+'</p>'
						+'</div>'
					+'</div>'
					+'<div class="user-info-button">'
						+'<a href="javascropt:;" class="select-file" title="分享文件">分享文件</a>'
						+'<a href="javascropt:;" title="删除好友">删除好友</a>'
					+'</div>'
				+'</div>'
        	}else{
        		html = 
	        	'<div class="user-info-main">'
					+'<div class="user-info-summary">'
						+'<div class="userPhoto">'
							+'<img alt="" src="${pageContext.request.contextPath}/static/avatars/user.jpg">'
						+'</div>'
						+'<div class="userName">'+friends[$(this).index()].remark+'</div>'
					+'</div>'
					+'<div class="user-info-detail clearfix">'
						+'<div class="title">'
							+'<p>备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注：</p>'
							+'<p>昵&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;称：</p>'
							+'<p>大岭山中学网盘账号：</p>'
						+'</div>'
						+'<div class="text">'
							+'<p>'
								+friends[$(this).index()].remark
								+'<a href="javascript:;" class="remarkButton" title="修改备注"></a>'
							+'</p>'
							+'<p class="noText">--</p>'
							+'<p>'+friends[$(this).index()].encryptionName+'</p>'
						+'</div>'
					+'</div>'
					+'<div class="user-info-button">'
						+'<a href="javascropt:;" class="select-file" title="分享文件">分享文件</a>'
						+'<a href="javascropt:;" title="删除好友">删除好友</a>'
					+'</div>'
				+'</div>'
        	}
        }else if(friends[$(this).index()].nickname != "-"){
        	$("#remark").val("");
        	html = 
	        '<div class="user-info-main">'
				+'<div class="user-info-summary">'
					+'<div class="userPhoto">'
						+'<img alt="" src="${pageContext.request.contextPath}/static/avatars/user.jpg">'
					+'</div>'
					+'<div class="userName">'+friends[$(this).index()].nickname+'</div>'
				+'</div>'
				+'<div class="user-info-detail clearfix">'
					+'<div class="title">'
						+'<p>备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注：</p>'
						+'<p>昵&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;称：</p>'
						+'<p>大岭山中学网盘账号：</p>'
					+'</div>'
					+'<div class="text">'
						+'<p class="noText">'
							+'<a href="javascript:;" title="点击添加备注" note-type="user-remark-button">点击添加备注</a>'
						+'</p>'
						+'<p>'+friends[$(this).index()].nickname+'</p>'
						+'<p>'+friends[$(this).index()].encryptionName+'</p>'
					+'</div>'
				+'</div>'
				+'<div class="user-info-button">'
					+'<a href="javascropt:;" class="select-file" title="分享文件">分享文件</a>'
					+'<a href="javascropt:;" title="删除好友">删除好友</a>'
				+'</div>'
			+'</div>'
        }else{
        	$("#remark").val("");
        	html = 
	        '<div class="user-info-main">'
				+'<div class="user-info-summary">'
					+'<div class="userPhoto">'
						+'<img alt="" src="${pageContext.request.contextPath}/static/avatars/user.jpg">'
					+'</div>'
					+'<div class="userName">'+friends[$(this).index()].encryptionName+'</div>'
				+'</div>'
				+'<div class="user-info-detail clearfix">'
					+'<div class="title">'
						+'<p>备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注：</p>'
						+'<p>昵&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;称：</p>'
						+'<p>大岭山中学网盘账号：</p>'
					+'</div>'
					+'<div class="text">'
						+'<p class="noText">'
							+'<a href="javascript:;" title="点击添加备注" note-type="user-remark-button">点击添加备注</a>'
						+'</p>'
						+'<p class="noText">--</p>'
						+'<p>'+friends[$(this).index()].encryptionName+'</p>'
					+'</div>'
				+'</div>'
				+'<div class="user-info-button">'
					+'<a href="javascropt:;" class="select-file" title="分享文件">分享文件</a>'
					+'<a href="javascropt:;" title="删除好友">删除好友</a>'
				+'</div>'
			+'</div>'
        }
        
		$(".user-info-mainbox").html(html);
	});
	
	$(".user-info-mainbox").on("click",".addFriend",function(){
		if(!$(this).hasClass("added")){
			var index = $(".addFriend").index(this);
			console.log(application[index].applicant)
			$.ajax({
				url : "agree-application.action",
				data: {
					applicant : application[index].applicant,
				},
				dataType: "json",
				success : function(data){
					if(data.status == 0){
						$(".addFriend").eq(index).addClass("added");
						$(".addFriend").eq(index).text(data.msg);
						$(".header-tabs a").eq(1).click();
					}else{
						alert(data.msg);
					}
				}
			});
		}
	});
	
	$(".user-info-mainbox").on("click","a",function(){
		if($(this).attr("note-type") == "user-remark-button" || $(this).hasClass("remarkButton")){
			var index = layer.open({
				type: 2,
				area: ['444px','207px'],
				title: '设置备注',
				skin:'mySkin',
				cornerRadius:'8',
				content:"/nebula/set-remark.action?set_remark="+$("#set-remark").val()
					+"&remark="+$("#remark").val()+"&count="+_count
			});
		}else if($(this).hasClass("select-file") || $(this).hasClass("shareFile")){
			var username = "";
			if($(this).hasClass("select-file")){
				username = friends[_count].username;
			}else if($(this).hasClass("shareFile")){
				var data_index = $(this).attr("data-index");
				username = application[data_index].applicant;
			}
			var index = layer.open({
				type: 2,
				area: ['771px','470px'],
				title: '文件列表',
				skin:'mySkin',
				content:"/nebula/file-share.action?username="+username
			});
		}else{
			layer.confirm("<div style='text-align: center;padding: 22px 22px 22px'>确认要删除好友\""+friends[_count].encryptionName+"\"吗？</div>",
				{title:"提示",skin:"mySkin",area:["482px","173px"]},
			function(index) {
				$.ajax({
					url : "/nebula/friends/delete-friend.action",
					data : {
						friendname : friends[_count].username,
					},
					dataType: "json",
					success: function(data){
						if(data.status == 0){
							parent.layer.msg("成功删除好友\""+friends[_count].encryptionName+"\"",{time:2000,icon:1,offset:"t"});
							_count = -1;
							$(".header-tabs a").eq(1).click();
							$(".user-info-mainbox").html("");
						}
					}
				});
				layer.close(index);
			});
		}
	});
	
	$(".operate-downlist-item").click(function(){
		var id = $(this).attr("data-id");
		layer.confirm("<div style='text-align: center;padding: 22px 22px 22px'>确认要删除会话吗？</div>",
				{title:"提示",skin:"mySkin",area:["482px","173px"]},
			function(index) {
				$.ajax({
					type: "post",
					url: "delete-session-list.action",
					data: {
						id : id
					},
					dataType: "json",
					success : function(_data){
						if(_data.status == 0){
							parent.layer.msg(_data.msg,{icon:1,time:2000,offset: "t"});
							$(".header-tabs a").eq(0).click();
						}else{
							parent.layer.msg(_data.msg,{icon:2,time:2000,offset: "t"});
						}
					}
				});
				layer.close(index);
			});
	});
	
	$(".sharelist-container").on("mouseenter","li",function(){
		$(".sharelist-container li").removeClass("hover");
		$(this).addClass("hover");
	});
	
	$(".sharelist-container").on("mouseleave","li",function(){
		$(".sharelist-container li").removeClass("hover");
	});
	
	$(".session-content-wrap").on("click",".session-list-item",function(){
		$(".header-show").show();
		$(".sharelist-shareViews").show();
		$(".module-sharelist").show();
		$(this).find(".new-num-session").remove();
		_sessionCount = $(this).index();
		$.ajax({
			type: "post",
			url: "get-share-list.action",
			data: {
				id : $(this).attr("id").trim(),
			},
			dataType: "json",
			success : function(_data){
				var html = "";
				$.each(_data.data,function(index,content){
					html +=
					'<li data-id="'+content.isDistributors+'">'
						+'<div class="sharelist-item-checkbox">'
							+'<input class="mgc mgc-primary" type="checkbox" name="'+content.id+'" id="check-one" data-id="'+content.fileIdGroup+'" data-multi="'+content.isMulti+'">'
						+'</div>'
						+'<div class="sharelist-item-name">'
							+'<div class="sharelist-item-title">'
								+'<i class="ico global-icon-16" style="background: url('+content.icon+')"></i>'
								+'<span class="global-ellipsis sharelist-item-title-name">'
									+'<a href="javascrit:;" class="enabled" title="'+content.title+'">'+content.title+'</a>'
								+'</span>'
							+'</div>'
						+'</div>'
						+'<div class="sharelist-item-size">'+content.size+'</div>'
						+'<div class="sharelist-item-sname global-ellipsis">'+content.distributors+'</div>'
							+'<div class="sharelist-item-date global-ellipsis" title="'+content.time+'">'+content.sharingTime+'</div>'
					+'</li>';
				});
				
				$(".sharelist-container ul").html(html);
			}
		});
	});
	
	$(".sharelist-columns").on("click","#check-all",function(){
		if($(this).is(":checked")){
			$("input[id=check-one]").each(function(){
				$(this).prop("checked",true);
				$(this).parents("li").addClass("on");
			});
			$(".btn-secondary-outline").addClass("disabled");
			$(".sharelist-operate-btns").show();
		}else{
			$("input[id=check-one]").each(function(){
				$(this).removeAttr("checked");
				$(this).parents("li").removeClass("on");
			});
			$(".btn-secondary-outline").removeClass("disabled");
			$(".sharelist-operate-btns").hide();
		}
	});
	
	$(".sharelist-container").on("click","#check-one",function(){
		if($(this).is(":checked")){
			if($("input[id=check-one]").size() == $("input[id=check-one]:checked").size()){
				$("#check-all").prop("checked",true);
			}
			$(this).parents("li").addClass("on");
			$(".sharelist-operate-btns").show();
			
			var valArr = [] , j , k;
			$("input[id=check-one]:checked").each(function(index,content){
				valArr[index] = $(this).parents("li").attr("data-id");
			});
			for(i = 0;i < valArr.length;i++){
				if(valArr[i] == 1) j = 1;
				else if(valArr[i] == 0) k = 1;
			}
			if(j == 1 && k == 1){
				$(".btn-secondary-outline").addClass("disabled");
			}else if(j == 1){
				$(".btn-secondary-outline").removeClass("disabled");
				$(".btn-secondary-outline").eq(0).addClass("disabled");
			}else if(k == 1){
				$(".btn-secondary-outline").removeClass("disabled");
				$(".btn-secondary-outline").eq(2).addClass("disabled");
			}
			
			if($("input[id=check-one]:checked").size() > 1){
				$(".btn-secondary-outline").eq(1).addClass("disabled");
			}
		}else{
			$(this).parents("li").removeClass("on");
			$("#check-all").removeAttr("checked");
			
			var valArr = [] , arr = [] , j , k;
			$("input[id=check-one]:checked").each(function(index,content){
				valArr[index] = $(this).parents("li").attr("data-id");
			});
			for(i = 0;i < valArr.length;i++){
				if(valArr[i] == 1) j = 1;
				else if(valArr[i] == 0) k = 1;
			}
			if(j == 1 && k == 1){
				$(".btn-secondary-outline").addClass("disabled");
			}else if(j == 1){
				$(".btn-secondary-outline").removeClass("disabled");
				$(".btn-secondary-outline").eq(0).addClass("disabled");
			}else if(k == 1){
				$(".btn-secondary-outline").removeClass("disabled");
				$(".btn-secondary-outline").eq(2).addClass("disabled");
			}
		}
		
		if($("input[id=check-one]:checked").size() == 0){
			$(".sharelist-operate-btns").hide();
		}
		
		if($("input[id=check-one]:checked").size() > 1){
			$(".btn-secondary-outline").eq(1).addClass("disabled");
		}
	});
	
	$(".btn-secondary-outline").click(function(){
		if($(this).attr("data-type") == "save"){
			var valArr = [];
			$("input[id=check-one]:checked").each(function(i){
				valArr[i] = $(this).attr("data-id");
			})
			console.log(valArr);
			var index = layer.open({
				type: 2,
				area: ['520px','300px'],
				fix: false, //不固定
				title: "保存到大岭山中学网盘",
				skin : "mySkin",
				content:"/nebula/directory.action?valArr="+valArr+"&type=fsave"
			});
		}else if($(this).attr("data-type") == "download"){
			var valArr = [];
			$("input[id=check-one]:checked").each(function(i){
				if($(this).attr("data-id").length <= 11){
					alert("文件夹下载功能暂未开发");
					return false;
				}else if($(this).attr("data-id").length > 15){
					alert("暂不支持多文件下载");
				}else{
					valArr[i] = $(this).attr("data-id");
				}
				var url;
				if(valArr == ""){
					return false;
				}else if(valArr.length == 1){
					console.log("download");
					url = "/nebula/file/download.action;jsessionid=<%=session.getId()%>;code="+randomString(4)
					+"?fileId="+valArr[0];
					layer.msg('正在准备下载，请稍后...',{offset:"t"});
					window.location = url;
				}else{
					layer.confirm("文件打包过程可能需要很长一段时间，确定使用打包下载吗？（大文件不建议使用）",{title:"确定使用打包下载"},function(index){
						var i;
						$.ajax({
							type: "post",
							url: "/nebula/file/compress.action",
							data : {
								fileIdGroup : function(){
									return valArr;
								}
							},
							dataType : "json",
							beforeSend: function(){
								i = layer.msg('文件正在打包，打包过程时间较长，请耐心等待...', {icon: 16,shade: [0.5, '#f5f5f5'],scrollbar: false,offset: '0px', time:-1}) ;  
							},
							success : function(data){
								layer.close(i);
								if(data.status == 0){
									url = "/nebula/file/plDownload.action;jsessionid=<%=session.getId()%>;code="+randomString(4)
									+"?zipname="+data.data.zipname+"&ctm="+data.data.ctm;
									window.location = url;
								}else{
									layer.msg(data.msg);
								}
							}
						});
						layer.close(index);
					});
				}
			});
		}else{
			layer.confirm("<div style='text-align: center;padding: 25px 25px 22px'>删除分享的文件后，好友将无法再访问此文件。 <br>你确定要删除吗？</div>",{title:"删除",area: ['482px','197px'],skin:"mySkin"},function(index){
				var valArr = [];
				$("input[id=check-one]:checked").each(function(i){
					valArr[i] = $(this).attr("name");
				});
				$.ajax({
					type: "post",
					url: "del-share-list.action",
					data: {
						valArr : function(){
							return valArr;
						},
					},
					dataType: "json",
					success : function(_data){
						if(_data.status == 0){
							$(".session-content-wrap .session-list-item").eq(_sessionCount).click();
							$(".sharelist-operate-btns").hide();
							parent.layer.msg(_data.msg, {icon: 1,offset: 't', time:2000});
						}else{
							parent.layer.msg(_data.msg, {icon: 2,offset: 't', time:2000});
						}
					}
				});
				layer.close(index);
			});
		}
	});
});

function randomString(len){
	len = len || 32;
	var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
	var maxPos = $chars.length;
	var pwd = '';
	for (i = 0; i < len; i++) {
　　　　	pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
　　	}
　　	return pwd;
}
</script>
</body>
</html>
